import { Injectable } from '@angular/core';
import {HEROES} from "./mick-heroes";
import {Hero} from "./hero";
import {Observable,of} from "rxjs";
import {MessageService} from "./message.service";
import {HttpClient,HttpHandler} from "@angular/common/http";

@Injectable({
  providedIn: 'root'
})
export class HeroService {
  getHeroes():Observable<Hero[]>{
    return this.http.get<Hero[]>(this.heroesUrl)
  }
  constructor(private messageService:MessageService,private http:HttpClient) { }
  getHero(id:number):Observable<Hero>{
    this.messageService.add(`HeroService: fetched hero id=${id}`)
    return of(HEROES.find(hero=>hero.id===id))
  }
  private heroesUrl="ali/heroes"
}
